package com.mypro.dbUtil;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.Reader;

/**
 * @author user_xdd
 * @Date 2022-05-19 10:49
 * @description
 * @return
 */
public class DbUtil {
    public static SqlSession getSqlSession() {
        //获取MyBatis操作工具类  SqlSession
        try {
            Reader reader = Resources.getResourceAsReader("configuration.xml");
            SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
            SqlSessionFactory factory = builder.build(reader);
            SqlSession session = factory.openSession();
            return session;
        } catch (IOException e) {
            e.printStackTrace();
        }

        return null;
    }
}
